var fujiafy = {
		url: {
			saveFujiafyUrl: function() {
				return path + "/fujiafdy/saveFujiafy";
			},
			getFujiafdyUrl: function() {
				return path + "/fujiafdy/getFujiafdy";
			}
		},
		init: function() {
			fujiafy.getFujiafdy();
			fujiafy.bandFunction();
		},
		bandFunction: function() {
			$("#btnSubmit").on("click", function(){
				fujiafy.saveFujiafy();
			});
			$('#formSave').validator({
				fields: {
					'kaiyaoliang':'数量:integer[+];length(~8)',
					'jine':'金额:range[0~];length(~18)',
					'#daijianfei':"金额:range[0~];length(~11)",
					'#waipeifei':"金额:range[0~];length(~11)",
					'#zhensuowlf':"金额:range[0~];length(~11)",
					'#gerenwlf':"金额:range[0~];length(~11)",
					'#putongghf':"金额:range[0~];length(~11)",
					'#zhuanjiaghf':"金额:range[0~];length(~11)",
				}
			});
			$("input:visible[type=text]").focusout(function(){
				var jine = $(this).val();
				   jine = getFloatStr(jine);
				   $(this).val(jine);
			});
			function getFloatStr(num){  
			    num += '';  
			    num = num.replace(/[^0-9|\.]/g, ''); //清除字符串中的非数字非.字符
			    if(/^0+/) //清除字符串开头的0
			        num = num.replace(/^0+/, '');
			    if(!/\./.test(num)) //为整数字符串在末尾添加.00
			        num += '.00';  
			    if(/^\./.test(num)) //字符以.开头时,在开头添加0
			        num = '0' + num;  
			    num += '00';        //在字符串末尾补零  
			    num = num.match(/\d+\.\d{2}/)[0];    
			    return num;
			}; 
		},
		getFujiafdy: function() {
			$.post(fujiafy.url.getFujiafdyUrl(),{},function(result){
				if(result.succsess) {
					$(result.data).each(function(){
						switch (this.mingcheng) {
							case "代煎费":
								$("#daijianfei").val(this.danjia.toFixed(2));
								break;
							case "外配费":
								$("#waipeifei").val(this.danjia.toFixed(2));
								break;
							case "诊所物流费":
								$("#zhensuowlf").val(this.danjia.toFixed(2));
								break;
							case "个人物流费":
								$("#gerenwlf").val(this.danjia.toFixed(2));
								break;
							case "普通挂号费":
								$("#putongghf").val(this.danjia.toFixed(2));
								break;
							case "专家挂号费":
								$("#zhuanjiaghf").val(this.danjia.toFixed(2));
								break;
						}
					});
				}
			});
		},
		saveFujiafy: function(){
			var data = {
					"daijianfei": $("#daijianfei").val(),
					"waipeifei": $("#waipeifei").val(),
					"zhensuowlf": $("#zhensuowlf").val(),
					"gerenwlf": $("#gerenwlf").val(),
					"putongghf": $("#putongghf").val(),
					"zhuanjiaghf": $("#zhuanjiaghf").val()
					
			};
			$.post(fujiafy.url.saveFujiafyUrl(),data,function(result){
				notifySuccess("保存成功");
			});
		}
};

